package com.xiaotu.spider.pipeline;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

import com.xiaotu.common.model.HotTVModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

/**
 * @类名 APipeLine
 * @日期 2017年2月10日
 * @作者 高海军
 * @功能 热剧pipeline
 */
@Component("HotTVPipeline")
public class HotTVPipeline extends APipeline
{
	@Override
	protected void doProcess(ResultItems resultItems, Task task)
	{
		List<HotTVModel> tvList = resultItems.get(HotTVModel.class.getName());
		if (tvList == null || tvList.isEmpty())
			return;
		
		Map<String, HotTVModel> valueMap = new HashMap<String, HotTVModel>();
		for (HotTVModel tvHot : tvList)
			valueMap.put(DataRedisKeyUtils.getHotTVKey(tvHot), tvHot);
		
		String key = DataRedisKeyUtils
				.getKey(Constants.DataRedisKey.TV_NetHot_YYYYMMDD);
		cacheHandler.hMSet(key, valueMap);
		cacheHandler.setCacheTimeout(key);
	}
}